package com.ddf.publics.config;

import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.Semaphore;

@Configuration
public class BeanConfig  {

    @Bean
    public Semaphore toSemaphore(){
        return new Semaphore(1);
    }

    /*implements ErrorViewResolver*/
    /*@Override
    public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {
        String state = status.toString().substring(0,3);
        if("404".equals(state)){
            return new ModelAndView("/error/404.html");
        }else if("403".equals(state)){
            return new ModelAndView("/error/403.html");
        }else if("500".equals(state)){
            return new ModelAndView("/error/500.html");
        }else{
            return new ModelAndView("/error/404.html");
        }
    }*/
}
